package cn.wangyu.msblogadmin.common.exception;


import cn.wangyu.msblogadmin.common.result.ResponseCode;
import lombok.Getter;
import lombok.Setter;

/**
 * @author wangyu
 * @version 1.0
 * @date 2021/4/11 23:05
 */
@Getter
@Setter
public class BusinessException extends RuntimeException {

    /**
     * 异常代码
     */
    private ResponseCode responseCode;

    /**
     * 异常描述
     */
    private String message;

    public BusinessException(ResponseCode responseCode) {
        this.responseCode = responseCode;
        this.message = responseCode.getDesc();
    }

    public BusinessException(ResponseCode responseCode, String message) {
        super(message);
        this.responseCode = responseCode;
        this.message = message;
    }

    /**
     * 没有传递状态码则默认为 500：未知异常
     */
    public BusinessException(String message) {
        super(message);
        this.responseCode = ResponseCode.FAILED;
        this.message = message;
    }

    /**
     * 重写堆栈填充，不填充错误堆栈信息，提高性能
     */
    @Override
    public synchronized Throwable fillInStackTrace() {
        return this;
    }
}
